package week12;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;


public class Main1 {
	public static void main(String[] args) throws IOException
	{
		//201621123023
		Student aa = new Student(1,"aa",18,90);
		Student bb = new Student(2,"bb",19,95);
		Student cc = new Student(3,"cc",20,93);
		File file = new File("d:\\students.txt");
		PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
		pw.println(aa.getId()+"|"+aa.getName()+"|"+aa.getAge()+"|"+aa.getGrade());
		pw.println(bb.getId()+"|"+bb.getName()+"|"+bb.getAge()+"|"+bb.getGrade());
		pw.println(cc.getId()+"|"+cc.getName()+"|"+cc.getAge()+"|"+cc.getGrade());
		pw.close();
		BufferedReader br = new BufferedReader(new FileReader(file));
		String a = null; 
		while((a = br.readLine())!=null)
		{
			System.out.println(a);
		}
		br.close();
	}
}
class Student {
	private int id;
	private String name;
	private int age;
	private double grade;
	
	public Student(){
		
	}
	public Student(int id, String name, int age, double grade) {
		this.id = id;
		this.setName(name);
		this.setAge(age);
		this.setGrade(grade);
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		if (name.length()>10){
			throw new IllegalArgumentException("name's length should <=10 "+name.length());
		}
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		if (age<=0){
			throw new IllegalArgumentException("age should >0 "+age);
		}
		this.age = age;
	}
	public double getGrade() {
		return grade;
	}
	public void setGrade(double grade) {
		if (grade<0 || grade >100){
			throw new IllegalArgumentException("grade should be in [0,100] "+grade);
		}
		this.grade = grade;
	}
}
